<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
	*{margin:0;padding:0;}
	a{text-decoration:none;}
	.nav-ul{width:100%;height:50px;text-align:center;line-height:50px;background:#AAFFEE;}
	.nav-ul li{width:100px;float:left;margin-left:10px;list-style:none;cursor:pointer;position:relative}
	.ms-count{position:absolute; color:white;top: 9px;cursor:pointer;left: 637px;width:15px;height:15px;background: red; border-radius: 7px;font-size: 15px;text-align: center;line-height: 14px;}
	.active{background:blue;}
	.opt{border: 1px solid red;padding: 3px;background: red;color: white;cursor: pointer;}
	.opt_none{border: 1px solid red;padding: 3px;background: red;color: white;}
	.nav-main{margin:20px 0 0 20px;}
</style>
</head>
<body>
	<div class="cotent">
		<div class="nav">
			<ul class="nav-ul">
				<li dataType="order" class="active">我的订单</li>
				<li>我的账户</li>
				<li><a href="http://pro.houzhangbo.com/product">一元抢宝</a></li>
				<li dataType="ads" onclick="getDate();">我的收货地址</li>
				<li>我的email</li>
				<li dataType="msg">我的消息</li>
			</ul>
			<p class="ms-count" id="msg"><a  href="#" style="color:white;">1</a></p>
		</div>
		<div class="nav-main">	
			<table width=80% style="text-align:center;">
				<thead style="background:blue;">
					<tr>
						<td>序号</td>
						<td>订单号</td>
						<td>商品</td>
						<td>金额</td>
						<td>数量</td>
					</tr>
				</thead>
				<tbody style="margin-top:10px;">
					<tr>
						<td>1</td>
						<td>1234567</td>
						<td><a href="">xxxxxx</a></td>
						<td>12.00元</td>
						<td>X5</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
<script>
	
	$(function(){
		getMesCount();
		var num = 0;
		var i = setInterval(function() {
            num++%2?$('#msg').show():$('#msg').hide();
            if (num > 100)
                clearInterval(i);
        }, 1000);
		$('#msg').on('click',function(){
			 clearInterval(i);
		})
	});
	function timeGet(){
		var i = setInterval(function() {
			getMesCount();
        }, 15000);
	}
	$('.nav-ul li').on("click",function(){
		$('.nav-ul li').removeClass('active');
		$(this).addClass('active');
		navLib($(this).attr('dataType'));
	})
	function navLib(type){
		$.ajax({
            type: "POST",
            url: "user/getMainTag",
            data: {type:type},
            timeout: 1800000,  //30分钟的超时时间
            async: false,
            success: function(opResult){
                if('0000'==opResult.respCode){
                	initTab(type,opResult.returnList);
                } else {
                    alert(opResult.respMsg);
                }
            },
            error:function () {
            	alert('操作失败');
            }
        });
	}
	function getMesCount(name){
		$.ajax({
            type: "POST",
            url: "userMsg/getMsgByName",
            data: {userName:name},
            timeout: 1800000,  //30分钟的超时时间
            async: false,
            success: function(opResult){
                if('0000'==opResult.respCode){
                	$('#msg').find("a").html(opResult.returnStr)
                } else {
                    alert(opResult.respMsg);
                }
            },
            error:function () {
            	alert('操作失败');
            }
        });
	}
	function getDate(){
		$.ajax({
            type: "POST",
            url: "ads/getListByUserName",
            data: {},
            timeout: 1800000,  //30分钟的超时时间
            async: false,
            success: function(opResult){
                if('0000'==opResult.respCode){
                	if(undefined==obj||obj.length<=0){
                		alert('没有数据');
            			return false;
            		}
                	initTab(opResult.returnStr.split(','),opResult.cookie.split(','),opResult.returnList);
                } else {
                    alert(opResult.respMsg);
                }
            },
            error:function () {
            	alert('操作失败');
            }
        });
	}
	function initTab(type,obj){
		var str = '<table width=80% style="text-align:center;"><thead style="background:blue;"><tr>';
		str = str + '<td>序号</td>';
		str = str + getTabInfo(type,obj);
		/*for(i=0;i<head.length;i++){
			str = str + '<td>'+head[i]+'</td>';
		}
		str = str + '</tr></thead>';
		str = str + '<tbody style="margin-top:10px;">';
		for(i=0;i<bodys.length;i++){
			str = str + '<tr>';
			str = str + '<td>'+(i+1)+'</td>';
			var body = bodys[i];
			for(j=0;j<bean.length;j++){
				str = str + '<td>'+body[bean[j]]+'</td>';
			}
			str = str + '</tr>';
		}*/
		str = str + '</tbody></table>';
		$('.nav-main table').remove();
		$('.nav-main').append(str);
	}
	function getTabInfo(type,obj){
		var str = '';
		if('order'==type){
			str = str + '<td>订单号</td><td>商品</td><td>价格</td><td>数量</td><td>状态</td><td>操作</td>';
			str = str + '</tr></thead>';
			for(i=0;i<obj.length;i++){
				str = str + '<tr>';
				str = str + '<td>'+(i+1)+'</td>';
				str = str + '<td>'+obj[i].orderNo+'</td>';
				str = str + '<td>'+obj[i].proId+'</td>';
				str = str + '<td>'+obj[i].price+'</td>';
				str = str + '<td>'+obj[i].sum+'</td>';
				str = str + '<td>'+obj[i].status+'</td>';
				str = str + '<td><a class="opt" onclick="">操作</a></td>';
				str = str + '</tr>';
			}
		}else if('ads'==type){
			str = str + '<td>地址</td><td>电话</td><td>收件人</td><td>状态</td><td>操作</td>';
			str = str + '</tr></thead>';
			for(i=0;i<obj.length;i++){
				str = str + '<tr>';
				str = str + '<td>'+(i+1)+'</td>';
				str = str + '<td>'+obj[i].adsInfo+'</td>';
				str = str + '<td>'+obj[i].adsPhone+'</td>';
				str = str + '<td>'+obj[i].adsReve+'</td>';
				str = str + '<td>'+obj[i].status+'</td>';
				str = str + '<td><a class="opt">操作</a></td>';
				str = str + '</tr>';
			}
		}else if('msg'==type){
			str = str + '<td>消息</td><td>状态</td><td>操作</td>';
			str = str + '</tr></thead>';
			for(i=0;i<obj.length;i++){
				str = str + '<tr>';
				str = str + '<td>'+(i+1)+'</td>';
				str = str + '<td>'+obj[i].message+'</td>';
				if(0==obj[i].status){
					str = str + '<td>未查看</td>';
					str = str + '<td><a class="opt" onclick="checkMsg('+obj[i].id+')">查看</a></td>';
				}else{
					str = str + '<td>已查看</td>';
					str = str + '<td><a class="opt_none" >查看</a></td>';
				}
				str = str + '</tr>';
			}
		}
		return str;
	}
	function checkMsg(id){
		$.ajax({
            type: "POST",
            url: "userMsg/checkMsg",
            data: {id:id},
            timeout: 1800000,  //30分钟的超时时间
            async: false,
            success: function(opResult){
                if('0000'==opResult.respCode){
                	alert('成功')
                } else {
                    alert(opResult.respMsg);
                }
            },
            error:function () {
            	alert('操作失败');
            }
        });
	}
</script>
</body>
</html>